import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ColorCountProvider extends ChangeNotifier {
  int _count = 0;

  String _color = 'black';

  String get color => _color;

  set color(String color) {
    _color = color;

    notifyListeners();
  }

  String get value => '$_color $_count';

  void plus() {
    _count++;

    notifyListeners();
  }
}

class ChangeNotifyProxyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('ChangeNotifyProxyProvider')),
      body: Center(
        child: _CountLabel(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => context.read<ColorCountProvider>().plus(),
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

class _CountLabel extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var count = context.select<ColorCountProvider, String>((p) => p.value);
    return Text('$count');
  }
}
